package com.fuxin.hanfu.service;

import com.fuxin.hanfu.domain.Admin;
import com.fuxin.hanfu.domain.Admin;
import com.fuxin.hanfu.mapper.AdminMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AdminService {
    @Resource
    private AdminMapper adminMapper;

    public List<Admin> findList() {
        return adminMapper.selectByExample(null);
    }

    public Admin findById(Integer userId) {
        return adminMapper.findById(userId);
    }

    public Integer insert(Admin admin) {
        try {
            return adminMapper.insert(admin);
        } catch (Exception e) {
            // 记录日志
            System.err.println("Error inserting admin: " + e.getMessage());
            throw e; // 重新抛出异常以便上层处理
        }

    }

    public Integer update(Admin admin) {
        return adminMapper.update(admin);
    }

    public Integer delete(Integer userId) {
        return adminMapper.delete(userId);
    }


    public Integer insertUser(Admin admin) {
        return adminMapper.insertUser(admin);

    }

    public Admin findByEmail(String email) {

        return null;
    }


    public Admin findByUsernameAndPassword(String username, String password) {
        // 这里应添加密码加密验证的逻辑，比如使用BCrypt
        Admin admin = adminMapper.findByUsername(username);
        if (admin != null && admin.getPassword().equals(password)) { // 注意：这里不应直接比较明文密码
            return admin;
        }
        return null;
    }
}
